package com.example.demo.vo;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * PageForm
 * </p>
 *
 * @author fyh
 * @since 2019/11/26 17:31
 */
public class PageForm<T> implements Serializable {
    /**
     * 页码
     */
    private Integer page;
    /**
     * 每页条数
     */
    private Integer limit;
    /**
     * 排序方式
     */
    private List<OrderItem> orders;

    private static final Integer DEFAULT_PAGE = 1;
    private static final Integer DEFAULT_Limit = 15;

    public PageForm() {
    }

    public Page<T> createPage() {
        Page<T> objectPage = new Page<>(ObjectUtils.isEmpty(this.page) ? DEFAULT_PAGE : this.page, ObjectUtils.isEmpty(this.limit) ? DEFAULT_Limit : this.limit);
        objectPage.setOrders(orders);
        return objectPage;
    }


    public PageForm(Integer page, Integer limit, List<OrderItem> orders) {
        this.page = page;
        this.limit = limit;
        this.orders = orders;
    }

    public Integer getPage() {
        return this.page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getLimit() {
        return this.limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public List<OrderItem> getOrders() {
        return this.orders;
    }

    public void setOrders(List<OrderItem> orders) {
        this.orders = orders;
    }
}
